import Vue from 'cheways-vue'
import places2 from './places.json' //每个空位的组件
import dragDrop from '../../nopack/drag-drop2.js'

dragDrop.ajaxPlaces(places2, function(p) {
	var places = p.slice(0, 7);
	dragDrop.init(places, function() {
		window.vm = new Vue({
			el: '#app',
			data: {
				components: [],
				places: places,
				showBindMessage: false,
				showBindGuide: false,
			},
			mounted: function() {
				var e = this,
					vm = this;
				mui.init({
					pullRefresh: {
						container: "#refreshContainer",
						down: {
							callback: function() {
								if(app.hasNoDev()) {
									mui("#refreshContainer").pullRefresh().endPulldownToRefresh();
									return;
								}
								app.getHomePageInfo(function() {
									mui("#refreshContainer").pullRefresh().endPulldownToRefresh();
									app.boardcast('lockRefresh')
									mui.toast("首页信息已刷新");
								}, function() {
									mui("#refreshContainer").pullRefresh().endPulldownToRefresh();
								})
							}
						}
					}
				});
				if(localStorage.getItem('showBindMessage') == 'true') {
					vm.showBindMessage = true;
				} else {
					vm.showBindMessage = false;
				}
				vm.showBindGuide = false;
				if(sessionStorage.getItem('carIsBind') == null) {

				} else {
					vm.showBindGuide = true;
				}
			},
			methods: {
				dragOver: dragDrop.dragOver,
				drop: dragDrop.drop,
				getPlaces: dragDrop.getPlaces,
				bindCar: function() {
					this.showBindMessage = false;
					vm.openWindow({
						url: '../../build/my-cars/my-cars.html'
					});
				},
				cancelBind: function() {
					this.showBindMessage = false;
					this.showBindGuide = true;
					localStorage.setItem('showBindMessage', false);
				},
		}
		});
	});
})